#region Usings
using System.Collections.Generic;
using System.Collections.ObjectModel;
#endregion

namespace BK.Model
{
    public class BaseTreeNodeEntity<TParent> : BaseBkEntity where TParent : BaseTreeNodeEntity<TParent>
    {
        #region Instance Methods
        protected string CalculateFullName()
        {
            string result = Name;
            TParent parent = Parent;
            while (parent != null)
            {
                result += "\\" + parent.Name;
                parent = parent.Parent;
            }

            return result;
        }

        protected int CalculateNestingLevel()
        {
            int result = 0;
            BaseTreeNodeEntity<TParent> parent = Parent;
            while (parent != null)
            {
                result++;
                parent = parent.Parent;
            }

            return result;
        }
        #endregion

        public BaseTreeNodeEntity()
        {
            ChildNodes = new List<BaseTreeNodeEntity<TParent>>();
        }

        #region Instance Properties
        public virtual IList<BaseTreeNodeEntity<TParent>> ChildNodes { get; set; }

        public string FullName { get; set; }
        public string Name { get; set; }
        public TParent Parent { get; set; }
        public int? ParentId { get; set; }
        #endregion
    }
}